/**
 * 负责将Babel等编译工具解析出的结果整合成一个对象，这里用的是esbuild
 */
const FRAGMENT = "__MYREACT_FRAGMENT";

const createTextElement = (text) => ({
  type: "TEXT_ELEMENT",
  props: {
    nodeValue: text,
  },
  // 为了让处理起来更加简便
  children: [],
});

const createElement = (type, props, ...children) => ({
  type,
  props,
  children: children.map((child) =>
    typeof child === "object" ? child : createTextElement(child)
  ),
});

export default {
  FRAGMENT,
  createTextElement,
  createElement,
};
